package cn.rongdao.jrkabao.ui.message;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mifengkong.frtools.http.request.callback.FRBaseObserver;
import com.mifengkong.frtools.ui.activity.FRStartActivity;
import com.mifengkong.frtools.util.FRString;
import com.mifengkong.frwidget.titlebar.TitleBarUIComponent;

import butterknife.BindView;
import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.base.BaseAutoFinishActivity;
import cn.rongdao.jrkabao.bean.message.MessageDetailsBean;
import cn.rongdao.jrkabao.model.message.MessageDetailsModel;


/**
 * Created by jack on 2017/8/21
 */

public class MessageDetailsActivity extends BaseAutoFinishActivity {

    public static final String MESSAGE_ID = "message_id";

    public static void start(Context context, String messageId) {
        Bundle bundle = new Bundle();
        bundle.putString(MESSAGE_ID, messageId);
        FRStartActivity.start(context, MessageDetailsActivity.class, bundle);
    }

    @BindView(R.id.amd_titlebar)
    TitleBarUIComponent titleBarUIComponent;
    @BindView(R.id.amd_ll_message)
    LinearLayout llMessage;
    @BindView(R.id.amd_tv_title)
    TextView tvTitle;
    @BindView(R.id.amd_tv_time)
    TextView tvTime;
    @BindView(R.id.amd_tv_content)
    TextView tvContent;

    private String messageId;

    @Override
    protected int layoutRes() {
        return R.layout.activity_message_details;
    }

    @Override
    protected void initView() {
        super.initView();
        initTitleBar();
        messageId = getIntent().getStringExtra(MESSAGE_ID);
        initData();
    }

    private void initData() {
        if (!FRString.isEmpty(messageId)) {
            MessageDetailsModel.getInstance().execute(messageId, new FRBaseObserver<MessageDetailsBean>(this, "加载中，请稍后...") {
                @Override
                protected void onBaseNext(MessageDetailsBean data) {
                    llMessage.setVisibility(View.VISIBLE);
                    tvTitle.setText(FRString.valueOf(data.getHead()));
                    tvTime.setText(FRString.valueOf(data.getCreate_time()));
                    tvContent.setText(FRString.valueOf(data.getContent()));
                }
            });
        }
    }

    private void initTitleBar() {
        titleBarUIComponent.initTitle("消息内容");
        titleBarUIComponent.setBackgroundColor(ContextCompat.getColor(thisActivity(), R.color.colorPrimary));
        titleBarUIComponent.initLeftBack(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
